home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / usenet / volume2 / pig < prev    next >
Encoding:
Internet Message Format  |  1987-08-28  |  3.0 KB

  1. Path: uunet!seismo!rutgers!ucla-cs!zen!ucbvax!decvax!tektronix!tekgen!tekred!games-request
  2. From: games-request@tekred.TEK.COM
  3. Newsgroups: comp.sources.games
  4. Subject: v02i033:  pig - simple pig-latin translator
  5. Message-ID: <1546@tekred.TEK.COM>
  6. Date: 29 Aug 87 00:05:27 GMT
  7. Sender: billr@tekred.TEK.COM
  8. Lines: 92
  9. Approved: billr@tekred.TEK.COM
  10.  
  11. Submitted by: root <ihnp4!killer!ozdaltx!root>
  12. Comp.sources.games: Volume 2, Issue 33
  13. Archive-name: pig
  14.  
  15.     [Here's a simple pig-latin translator in lex.  I added
  16.      the Makefile and fixed a bug.  It's my recollection that
  17.      pig-latin is actual a little more complex than this, but
  18.      hey, I don't write 'em - I just post 'em.  -br]
  19.     [P.S. How about some more games?  My queue is empty.]
  20.  
  21. [[This is a lex file for a pig-latin translator. If you don't
  22. know what pig-latin is or are too young to remember... It
  23. was a "language" popular in the 40-50's. The rules are
  24. simple, move the first letter of each word to the end of the
  25. word and add an 'a'. For example; "pig-latin" becomes
  26. "igpa-atinla". I wrote this as an exercise trying to learn
  27. lex. It needs some cleaning up, but it works as is. Words
  28. that are all capitals are not parsed correctly, yet. Anyway,
  29. enjoy.
  30.  
  31.     ************************************************
  32.     * Scotty                     *  Adapt          *
  33.     * ihnp4!killer!ozdaltx!sysop *     Enjoy       *
  34.     * "Ad Venerem Securiorem"    *        Survive  *]]
  35. ----------------------
  36. #! /bin/sh
  37. # This is a shell archive.  Remove anything before this line, then unpack
  38. # it by saving it into a file and typing "sh file".  To overwrite existing
  39. # files, type "sh file -c".  You can also feed this as standard input via
  40. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  41. # will see the following message at the end:
  42. #        "End of shell archive."
  43. # Contents:  Makefile pig.l
  44. # Wrapped by billr@tekred on Fri Aug 28 16:56:20 1987
  45. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  46. if test -f Makefile -a "${1}" != "-c" ; then 
  47.   echo shar: Will not over-write existing file \"Makefile\"
  48. else
  49. echo shar: Extracting \"Makefile\" \(102 characters\)
  50. sed "s/^X//" >Makefile <<'END_OF_Makefile'
  51. X# Makefile for pig - Pig-Latin translator
  52. X
  53. Xpig:    pig.l
  54. X    lex pig.l
  55. X    cc -o pig lex.yy.c -ll
  56. X    rm lex.yy.c
  57. END_OF_Makefile
  58. if test 102 -ne `wc -c <Makefile`; then
  59.     echo shar: \"Makefile\" unpacked with wrong size!
  60. fi
  61. # end of overwriting check
  62. fi
  63. if test -f pig.l -a "${1}" != "-c" ; then 
  64.   echo shar: Will not over-write existing file \"pig.l\"
  65. else
  66. echo shar: Extracting \"pig.l\" \(331 characters\)
  67. sed "s/^X//" >pig.l <<'END_OF_pig.l'
  68. X/* PIG - a pig-latin translator */
  69. X
  70. X%{
  71. X#include <ctype.h>
  72. Xchar *c, start;
  73. X%}
  74. X%%
  75. X[A-Za-z]+    {
  76. X    if(yyleng >=2){
  77. X        c=yytext;
  78. X        if(isupper(yytext[0]))
  79. X            start = tolower(yytext[0]);
  80. X        else
  81. X            start = yytext[0];
  82. X        c++;
  83. X        if(isupper(yytext[0]))
  84. X            *c=toupper(*c);
  85. X        printf("%s%ca",c,start);
  86. X    } else {
  87. X        ECHO;
  88. X    }
  89. X}
  90. X%%
  91. Xmain()
  92. X{
  93. X    yylex();
  94. X}
  95. END_OF_pig.l
  96. if test 331 -ne `wc -c <pig.l`; then
  97.     echo shar: \"pig.l\" unpacked with wrong size!
  98. fi
  99. # end of overwriting check
  100. fi
  101. echo shar: End of shell archive.
  102. exit 0
  103.